package com.project.collectAPI;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.project.collectAPI.comm.*;
import com.project.collectAPI.config.DataSourceConfig;
import com.project.collectAPI.entity.Curtask;
import com.project.collectAPI.entity.StoreItem;
import com.project.collectAPI.entity.StoreJsonConfig;
import com.project.collectAPI.entity.SuperMarket.SuperMarketFirstClass;
import com.project.collectAPI.service.CurtaskforsupermarketService;
import com.sun.jna.platform.win32.WinDef;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import lombok.SneakyThrows;
import lombok.val;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;

import java.awt.*;
import java.io.FileInputStream;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import javafx.scene.image.Image;

import javax.annotation.Resource;


@SpringBootApplication
public class collectAPIApplication{

    //volatile修饰符用来保证其它线程读取的总是该变量的最新的值
    public static volatile boolean exit = false;

    public static void main(String[] args) throws Exception {

            //启动程序
            //无障碍模式启动1
            SpringApplicationBuilder builder = new SpringApplicationBuilder(collectAPIApplication.class);
            builder.headless(false).run(args);

            try { TimeUnit.MILLISECONDS.sleep( 5000); } catch (InterruptedException e) { e.printStackTrace(); }

            Robot robot=new Robot();

            //测试
            /*Point point=AutoRobot.FindTargetImagePositon(robot,"收起2.png");
            System.out.println("查询是否有收起"+point);*/


            //测试检查，不用删除
            /*Point pointtest=AutoRobot.FindTargetImagePositon(robot,"wer1.png");
            if(pointtest.x!=-1 && pointtest.y!=-1){
                throw new Exception("首页wer1..停止循环");
            }
            pointtest=AutoRobot.FindTargetImagePositon(robot,"wer2.png");
            if(pointtest.x!=-1 && pointtest.y!=-1){
                throw new Exception("首页wer2..停止循环");
            }
            pointtest=AutoRobot.FindTargetImagePositon(robot,"w1car.png");
            if(pointtest.x!=-1 && pointtest.y!=-1){
                throw new Exception("购物车w1car..停止循环");
            }
            pointtest=AutoRobot.FindTargetImagePositon(robot,"w1收起.png");
            if(pointtest.x!=-1 && pointtest.y!=-1){
                throw new Exception("菜单w1收起..停止循环");
            }
            System.out.println("程序终止退出..........");
            System.exit(0);*/


            try {
                    //删除新品寻宝 -- 多店铺
                   /* Object pp=new Object();
                    String[] appPois=doWork.storeIds.split(",");
                    for (int i = 0; i < appPois.length;i++) {
                        String appPoiId=appPois[i];
                        new Thread(new Runnable() {
                            @SneakyThrows
                            @Override
                            public void run() {
                                synchronized (pp){
                                    doWork.BatchDelete("新品寻宝",appPoiId,false); //创建一级分类和二级分类
                                }
                            }
                        }).start();
                        //调用的方法删除需要时间执行过程
                        try { TimeUnit.MILLISECONDS.sleep( 200); } catch (InterruptedException e) { e.printStackTrace(); }
                    }*/

                    //开始任务
                    doWork.startDoTask(robot);

            } catch (Exception e) {
                e.printStackTrace();
            }

    } // main End




} //Class End
